home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / tse_mac1.zip / PCTAGS.S < prev    next >
Text File  |  1993-04-22  |  5KB  |  155 lines

  1. // emtoems
  2.  
  3. /* File Name...: Pctags.s                                                                     */
  4. /* Program Name: PCTags macro procedures for The SemWare Editor      */
  5. /* Version.....: 0.10                                                                                  */
  6. /* Author......: Ron Hockemeier                                                      */
  7.  
  8. /************************************************************************
  9.  
  10. TSE macros to search a PC-TAGS generated tagfile; retrieve the file_name
  11. and function_info; edit the file_name; and position the cursor at the
  12. row where the function is located.
  13.  
  14. Works with ONE tagfile
  15.  
  16. !!! NOTE: !!! If you add this to yout TSE.S file remove the procedures
  17. "GetWordAtCursor()" and "GetTextUntil()" as they duplicate procedures in
  18. the default TSE.S file.
  19.  
  20. You must change the sting assigned to "s_tagfile" (in proc pctags_main)
  21. to match the path and file name of your tagfile.
  22.  
  23. As written, the find used in these PC-TAGS procedures
  24. is case insensitive.
  25.  
  26. *************************************************************************/
  27.  
  28. string proc GetWordAtCursor()
  29.     // !!! from tse.s
  30.     string word[80] = ''
  31.  
  32.     PushBlock()                     // Save current block status
  33.     if MarkWord()                   // Mark the word
  34.         word = GetMarkedText()      // Get it
  35.     endif
  36.     PopBlock()                      // Restore block status
  37.     return (word)                   // Thats all, folks!
  38. end GetWordAtCursor
  39.  
  40. string proc GetTextUntil(string stopchar)
  41.     // !!! from tse.s
  42.     integer start = CurrPos()
  43.  
  44.     while CurrChar() <> Asc(stopchar) and CurrChar() >= 0 and Right()
  45.     endwhile
  46.  
  47.     return (GetText(start, CurrPos() - start))
  48. end gettextuntil
  49.  
  50.  
  51. proc Pctags_main( string s_word )
  52. // common procedure called by:
  53. //   Pctags_Auto()
  54. //   Pctags_Prompt()
  55.  
  56. string s_file[80]     // target file name to edit (including dir and path)
  57. string s_phrase[20]   // the target phrase
  58. string s_prefix[20]   // prefix of the the target phrase
  59. string s_suffix[20]   // suffix of the target phrase
  60.  
  61. string s_tagfile[30]  // path and name for the tagfile
  62.  
  63. s_tagfile = "c:\cl\pctags.tag"   // <==-- change for *YOUR* path and file
  64.  set( sound, off )
  65. if not editfile( s_tagfile )
  66.   message( "Can't find "+s_tagfile)
  67. else
  68.  
  69.   begfile()   // position to the start of the file
  70.               // paranoia error trap in case the file is in memory
  71.   if not lFind( s_word ,"i")
  72.     abandonfile()
  73.     message( "Can't find: "+s_word )
  74.   else
  75.     // position to the file name
  76.     wordright()
  77.     // grab the file name
  78.     s_file = GetTextUntil(' ')
  79.  
  80.     // position to the carat
  81.     lFind( '^',"i")
  82.     // position to the phrase
  83.     wordright()
  84.  
  85.     // grab the phrase in *two* ways
  86.     s_phrase = gettext( currpos(), 255 )
  87.     s_prefix = getwordatcursor()
  88.  
  89.     // position to the suffix
  90.     wordright()
  91.  
  92.     // grab the suffix
  93.     s_suffix = getwordatcursor()
  94.  
  95.     // bail out of the tagfile
  96.     abandonfile()
  97.  
  98.     if not editfile( s_file )
  99.       alarm()
  100.       message( "Can't find file: "+s_file )
  101.     else
  102.       begfile()   // position to the start of the file
  103.       // these finds are case insensitive               <==--
  104.       if find( s_phrase , "i" )  // use find to highlight
  105.         // Bingo!
  106.         ScrollToRow(Query(WindowRows)/2)
  107.  
  108.       // error trap -- try a different find in case non-relevant info
  109.       // on line was changed since PC-Tags was run
  110.       elseif find( s_prefix+" "+s_suffix  , "i" )  // use find to highlight
  111.         // Bingo!
  112.         ScrollToRow(Query(WindowRows)/2)
  113.       else
  114.         alarm()
  115.         message( "Can't find: "+s_phrase )
  116.       endif
  117.     endif
  118.   endif
  119. endif
  120.  
  121. end Pctags_main
  122.  
  123. proc pctags_auto()
  124. //  uses word at cursor for search
  125.  
  126. string s_cur_word[30]     // word we'll get at cursor
  127.  
  128. if not Length(GetWordAtCursor())
  129.   message( "Cursor is not on a word" )
  130. else
  131.   s_cur_word = GetWordAtCursor()
  132.   // give the rest of the task to our common procedure
  133.   Pctags_main( s_cur_word )
  134. endif
  135. end pctags_auto
  136.  
  137. proc pctags_prompt()
  138. //  prompts for a word to use in search
  139. string s_prom_word[30] = ""    // word you'll type-in
  140.  
  141. if Ask('PC-TAGS word? ', s_prom_word) AND Length( s_prom_word )
  142.   // give the rest of the task to our common procedure
  143.   // note: we're adding a space as we pass the word <==--
  144.   // delete the space if you want to use partial function names
  145.   Pctags_main( s_prom_word + " " )
  146. else
  147.   message( "Sorry.  Need a word" )
  148. endif
  149.  set( sound, on )
  150. end pctags_prompt
  151.  
  152. // demo keys
  153.  <alt a>    pctags_auto()
  154.  <Alt p>    pctags_prompt()
  155.